<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 
        form发送请求会跳转页面
        使用ajax完成无跳转的请求
     -->
    <script>
        // XmlHttpRequest()
        // 对象用来与服务端进行交互

        // 发送请求第一步
        // 1. 构建一个XMLHttpRequest()对象
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            console.log(xhr.readyState);
            if (xhr.readyState == 4) {
                console.log(xhr.responseText);
                var data = JSON.parse(xhr.responseText);
                console.log(data);
            }
        }
        xhr.open('get', 'https://cnodejs.org/api/v1/topics');
        xhr.send();
    </script>
</body>

</html>